package com.hhkj.admin.course.controller;

import com.hhkj.admin.course.domain.CourseBankType;
import com.hhkj.admin.course.model.req.CourseBankTypeReq;
import com.hhkj.admin.course.model.res.CourseBankTypeRes;
import com.hhkj.admin.course.service.biz.CourseBankTypeBizService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.LogTitlePrefix;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.valid.VList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程题库类型Controller
 *
 * @author ruoyi
 * @since 2023-05-11
 */
@LogTitlePrefix("课程题库类型")
@PermissionPrefix("train:courseBankType")
@RestController
@RequestMapping("/course/bank/type")
public class CourseBankTypeController extends BaseController<CourseBankType, CourseBankTypeReq, CourseBankTypeRes, CourseBankTypeBizService>
{

    /** 设置默认题库 */
    @Log(title = "禁用/启用", businessType = BusinessType.UPDATE)
    @PutMapping("/defaultBank")
    public AjaxResult updateDefaultBank(@RequestBody CourseBankTypeReq req)
    {
        return success(this.getBizService().updateDefaultFlag(req));
    }

    /** 启用/禁用 */
    @PreAuthorize("@ss.hasPermi(this, 'disable')")
    @Log(title = "禁用/启用", businessType = BusinessType.UPDATE)
    @PutMapping("/disable")
    public AjaxResult updateDisable(@RequestBody CourseBankTypeReq req)
    {
        return success(this.getBizService().updateDisable(req));
    }

    /** 查询课程题库类型列表 */
    @PostMapping("/list")
    public TableDataInfo list(@Validated(VList.class) @RequestBody CourseBankTypeReq req)
    {
        List<CourseBankTypeRes> list = this.getBizService().list(req);
        return getDataTable(list);
    }

    /** 查询课程题库类型列表 */
    @PostMapping("/enable/list")
    public TableDataInfo listEnable(@RequestBody CourseBankTypeReq req)
    {
        List<CourseBankTypeRes> list = this.getBizService().listEnable(req);
        return getDataTable(list);
    }
}
